package com.xca.rxjavademo.utils;

import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;

public class EditTextUtils {

    public static void clearFocus(EditText view)
    {
        view.clearFocus();
        InputMethodManager imm = (InputMethodManager) view.getContext().getSystemService(view.getContext().INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }

    public static void getFocus(EditText view)
    {
        view.requestFocus();
        InputMethodManager imm = (InputMethodManager) view.getContext().getSystemService(view.getContext().INPUT_METHOD_SERVICE);
        imm.showSoftInput(view, InputMethodManager.SHOW_FORCED);
        // 将光标定位在EditText末尾
        view.setSelection(view.getText().length());
    }
}
